From fd4dc0f446ce956aca32f4ebd44424d19b0ce7e4 Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 10 Mar 2004 18:35:00 +0000 Subject: [PATCH] Mark Bramel identified problems with NG Topo! only [A-Z][0-9] are allowed in waypoint names. --- gpsbabel/mkshort.c | 9 +++++---- gpsbabel/tpg.c | 29 ++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/gpsbabel/mkshort.c b/gpsbabel/mkshort.c index a6a87727d..7b653eb27 100644 --- a/gpsbabel/mkshort.c +++ b/gpsbabel/mkshort.c @@ -276,9 +276,6 @@ mkshort(void *h, const char *istring) cp = ostring; for (i=0;imustupper) { - tstring[i] = toupper(tstring[i]); - } *cp++ = tstring[i]; } } @@ -286,6 +283,11 @@ mkshort(void *h, const char *istring) *cp = 0; } + if (hdl->mustupper) { + for (tstring = ostring; *tstring; tstring++) { + *tstring = toupper(*tstring); + } + } /* * Eliminate chars on the blacklist. * Characters that aren't ASCII are never OK. @@ -343,7 +345,6 @@ mkshort(void *h, const char *istring) strcpy(&ostring[hdl->target_len] - strlen(np), np); } - if (hdl->must_uniq) { return mkshort_add_to_list(hdl, ostring); } diff --git a/gpsbabel/tpg.c b/gpsbabel/tpg.c index f8766f423..d62a43647 100644 --- a/gpsbabel/tpg.c +++ b/gpsbabel/tpg.c @@ -202,9 +202,10 @@ tpg_waypt_pr(const waypoint *wpt) double amt; short int elev; char tbuf[64]; - char c; + char c,ocount; char *shortname; char *description; + int i; /* these unknown 4 are probably point properties (color, icon, etc..) */ unsigned char unknown4[] = { 0x78, 0x56, 0x34, 0x12 }; @@ -262,10 +263,27 @@ tpg_waypt_pr(const waypoint *wpt) /* 1 bytes stringsize for shortname */ c = strlen(shortname); - fwrite(&c, 1, 1, tpg_file_out); - - /* shortname */ - fwrite(shortname, 1, c, tpg_file_out); + ocount = 0; + /* + * It's reported the only legal characters are upper case + * A-Z and 0-9. Wow. We have to make two passes: one to + * count and one to output. + */ + for (i = 0; i < c; i++) { + char oc = toupper(shortname[i]); + if (isalnum(oc) || oc == ' ') { + ocount++; + } + } + + fwrite(&ocount, 1, 1, tpg_file_out); + + for (i = 0; i < c; i++) { + char oc = toupper(shortname[i]); + if (isalnum(oc) || oc == ' ') { + fputc(oc, tpg_file_out); + } + } /* 8 bytes - longitude */ tpg_fwrite_double(lon, tpg_file_out); @@ -316,6 +334,7 @@ tpg_write(void) if (global_opts.synthesize_shortnames) { setshort_length(mkshort_handle, 32); setshort_whitespace_ok(mkshort_handle, 1); + setshort_mustupper(mkshort_handle, 1); } if (s > MAXTPGOUTPUTPINS) { -- 2.30.2